<?php
//echo "<pre>";
//print_r($_POST);
//echo "</pre>";

if(isset($_POST[txtClientId]) && $_POST[txtClientId] !='')
{
	$sql = "SELECT * FROM tb_clientinfo,tb_userinfo WHERE ui_clientId = ci_id  AND ci_id =".$_POST[txtClientId];
	$rows = $db->query($sql);
	$clientRecord = $db->fetch_array($rows);
	//print_r($clientRecord);
	if($clientRecord[ci_clientType] == "Reseller")
	{
		$styl = 'style="display:;"';
		$getSubs = "SELECT * FROM tb_reseller_subscription WHERE trs_clientId = ".$_POST[txtClientId];
		$resSubs = $db->query($getSubs);
		$subsRecord = $db->fetch_array($resSubs);
	}
	else
		$styl = 'style="display:none;"';
}
?>
<script language="javascript">
$(function() {
	$( "#txtSubStartDate" ).datepicker({
		changeMonth: true,
		changeYear: true,
		showOn: "button",
		buttonImage: "images/calendar.gif",
		buttonImageOnly: true,
		dateFormat : "dd/mm/yy"
	});
});

var ajax1=new sack();

//CHECKING UNIQUE DRIVER ID FOR ADMIN

function checkUser(tableName,condStr,val,id)
{
	qry = "select * from "+tableName+" where "+condStr+" = '"+val+"'";
		
	ajax1.requestFile = 'ajax_server.php?ajaxQry='+qry;
	//document.write(ajax1.requestFile);
	ajax1.onCompletion = function(){resultDevice(id)};
	ajax1.runAJAX();
}

function resultDevice(id)
{
  if(ajax1.response ==1 )
  {
  	alert("Date already Exist");
  	document.getElementById(id).value = '';
	document.getElementById(id).focus();
  }
	
}

Date.prototype.defaultView=function(){
var dd=this.getDate();
if(dd<10)dd='0'+dd;
var mm=this.getMonth()+1;
if(mm<10)mm='0'+mm;
var yyyy=this.getFullYear();
return String(dd+"\/"+mm+"\/"+yyyy)
}
function addMonth(d,month)
{
t = new Date (d);
var ed = new Date(new Date(t).setMonth(t.getMonth()+parseInt(month)));

return ed.defaultView();
} 
function showEndDate(sDate,durMonth)
{
	document.getElementById('txtEndDate').innerHTML += addMonth(sDate,durMonth);
}
function showHideSubsTable(val)
{
	if(val == "Reseller")
		document.getElementById('subsTable').style.display = '';
	else
		document.getElementById('subsTable').style.display = 'none';
}

</script>
<style type="text/css">

</style>
<div align="left" class="listofusers"><a href="#" onclick="location.href='?ch=viewReseller';">List of Users</a>&nbsp;</div>
<form name="frmUserRegister" id="frmUserRegister" action="?ch=Reseller" method="post" autocomplete="off">
<?php
if(isset($_POST[txtClientId]) && $_POST[txtClientId] !=''){
?>
	<input type="hidden" name="txtClientId" id="txtClientId" value="<?php echo $_POST[txtClientId];?>"/>  
<?php } ?>

	<div class="form_area"><!-- form area div start here -->
       <ul class="form">
            <li>
                <label>Reseller Name </label>
                <?php if(isset($_POST[txtClientId]) && $_POST[txtClientId] !=''){ ?>
                <input type="text" id="txtClientName" class="form_text" name="txtClientName" disabled="disabled" value="<?php echo $clientRecord[ci_clientName];?>"  />	
                <?php } else { ?>
                <input type="text" id="txtClientName" class="form_text" name="txtClientName" value="<?php echo $clientRecord[ci_clientName];?>" 
                onblur="checkUser('tb_clientinfo','ci_clientName',this.value,this.id);" />
             <?php } ?>
            </li>
            <li>
            	<label>Username</label>
                <?php
					if(isset($_POST[txtClientId]) && $_POST[txtClientId] !=''){
					?>
					  <input type="text" id="txtUsername" class="form_text" name="txtUsername" disabled="disabled" value="<?php echo $clientRecord[ui_username];?>"/>
					  <?php } else { ?>
					  <input type="text" id="txtUsername" class="form_text" name="txtUsername" value="<?php echo $clientRecord[ui_username];?>" onblur="checkUser('tb_userinfo','ui_username',this.value,this.id);" />
					 <?php } ?>
            </li>
            <li>
                <label>Password</label>
                <?php
					if(isset($_POST[txtClientId]) && $_POST[txtClientId] !=''){
					?>
				  <input type="password" id="txtPassword" class="form_text" name="txtPassword" disabled="disabled" value="<?php echo $clientRecord[ui_password];?>"/>
				  <?php } else { ?>
				  <input type="password" id="txtPassword" class="form_text" name="txtPassword" value="<?php echo $clientRecord[ui_password];?>" />
				   <?php } ?>
            </li>
            <li>
                <label>Land Line </label>
                <input type="text" id="txtCLandline" class="form_text" name="txtCLandline" value="<?php echo $clientRecord[ci_phoneNumber];?>" />
            </li>
            <li>
                <label>Mobile</label>
                <input type="text" id="txtCMobile" class="form_text" name="txtCMobile" value="<?php echo $clientRecord[ci_mobileNumer];?>" />
            </li>
            <li>
                <label>Email 1</label>
                <input type="text" id="txtCEmail1" class="form_text" name="txtCEmail1" value="<?php echo $clientRecord[ci_email1];?>" />
            </li>
            <li>
                <label>Email 2</label>
                <input type="text" id="txtCEmail2" class="form_text" name="txtCEmail2" value="<?php echo $clientRecord[ci_email2];?>" />
            </li>
            <li>
                <label>Website</label>
                <input type="text" id="txtCWebsite" class="form_text" name="txtCWebsite" value="<?php echo $clientRecord[ci_website];?>" />
            </li>
            <li>
                <label>Address</label>
                <textarea id="txtCAddress" class="text_area" name="txtCAddress" cols="40" rows="3"><?php echo $clientRecord[ci_address];?></textarea>
            </li>
        </ul>
		<p class="btn_area"> 
				<?php
				  if(isset($_POST[txtClientId]) && $_POST[txtClientId] !='')
					{
					?>
						<input type="submit" name="cmdSubmitUpdateClient" id="cmdSubmitUpdateClient" value="Update" class="save_btn" />  
				  <?php } else { ?>
						<input type="submit" name="cmdSubmitAddClient" id="cmdSubmitAddClient" value="Submit" class="save_btn" />
													 <input type="reset" value="Reset" class="save_btn" />
				  <?php } ?>	
      	</p>   
  </div>

        
</form>
 <script language="javaScript" type="text/javascript">

//You should create the validator only after the definition of the HTML form
  var frmvalidator  = new Validator("frmUserRegister");
  
  frmvalidator.addValidation("txtClientName","req","Please enter Client Name");
  frmvalidator.addValidation("txtClientName","minlen=5",	"Min length for Client Name is 5");
  frmvalidator.addValidation("txtClientName","alpha_s","Name can contain alphabetic chars only");
  
  
  frmvalidator.addValidation("txtUsername","req","Please enter Username");
  frmvalidator.addValidation("txtUsername","minlen=4",	"Min length for Username is 5");
  frmvalidator.addValidation("txtUsername","alpha_s","Name can contain alphabetic chars only");
  
  frmvalidator.addValidation("txtPassword","req","Please enter Password");
  frmvalidator.addValidation("txtPassword","minlen=8",	"Min length for Password is 8");
  
  frmvalidator.addValidation("txtCLandline","maxlen=50");
  frmvalidator.addValidation("txtCLandline","numeric","Please enter valid Landline number");
  
  frmvalidator.addValidation("txtCMobile","maxlen=50");
  frmvalidator.addValidation("txtCMobile","req","Please enter Mobile number");
  frmvalidator.addValidation("txtCMobile","numeric","Please enter valid Mobile number");

  frmvalidator.addValidation("txtCEmail1","maxlen=50");
  frmvalidator.addValidation("txtCEmail1","req","Please enter Email 1");
  frmvalidator.addValidation("txtCEmail1","email","Please enter valid Email 1");
  
  frmvalidator.addValidation("txtCEmail2","maxlen=50");
  frmvalidator.addValidation("txtCEmail2","email","Please enter valid Email 1");
  
  frmvalidator.addValidation("txtCAddress","maxlen=150");
  
</script>   
